package comoabejas

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

class AreaService {

    static transactional = true

    def serviceMethod() {

    }
    public Area saveObj(Area area){
		if(area.save(flush: true)){
			return area;
		}
    }
    
    def listObj(){
       def g = [instanceList: Area.list(), instanceTotal: Area.count()]
       return g;
    }
    def getObj(String id){
        def instance = Area.get(id)
        return instance
    }
    public void deleteObj(Area obj){
        obj.delete(flush: true)

    }
    
	def generateData = {
		
		List<Area> listaAreas = new ArrayList<Area>()
		listaAreas =  Area.list()
		
		for (Area a : listaAreas) {
			a.delete(flush : true)
		}

		Area area = new Area()
		area.setName("Buenos Aires")
		area.setType(AreaTypeConstants.CIUDAD)
		listaAreas.add(0, area)
		area = new Area()
		area.setName("Mar del Plata")
		area.setType(AreaTypeConstants.CIUDAD)
		listaAreas.add(1, area)
		
		try{
			for (Area a : listaAreas) {
				a.save(flush :true)
			}
			
		}catch (Exception e) {
			e.printStackTrace()
		}
	}
    
}
